package cn.terminus.web.customer.settledenterpriseinfo.controller;

import cn.terminus.client.customer.analysis.param.SettledEnterpriseAnalysisParam;
import cn.terminus.client.customer.analysis.result.CustomerNatureIndustryResultList;
import cn.terminus.client.customer.analysis.result.SettledEnterpriseLabelNumResult;
import cn.terminus.client.customer.settledenterpriseinfo.param.*;
import cn.terminus.client.customer.settledenterpriseinfo.result.SettledEnterpriseInfoResult;
import cn.terminus.client.customer.settledenterpriseinfo.service.SettledEnterpriseInfoService;
import cn.terminus.result.common.exception.ServiceException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.web.customer.analysis.SettledEnterpriseAnalysisQuery;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.web.customer.settledenterpriseinfo.form.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 入驻企业控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine SettledEnterpriseInfo $serviceComment
 * @since 2021-07-08 11:19:08
 */
@RestController
@RequestMapping("enterprise/settledEnterpriseInfo")
@Api(value = "入驻企业管理控制层")
public class SettledEnterpriseInfoController extends AbstractTerminusController {

    /**
     * 服务对象
     */
    @Resource
    private SettledEnterpriseInfoService settledEnterpriseInfoService;

    @ApiOperation(value = "入驻企业新增", httpMethod = "POST")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public TerminusResult<String> add(@RequestBody AddSettledEnterpriseInfoForm form) {
        AddSettledEnterpriseInfoParam param = BeanCopyUtils.copyProperties(form, AddSettledEnterpriseInfoParam.class);
        try {
            return settledEnterpriseInfoService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增入驻企业失败，原因：", e);
            return TerminusResult.fail("410002", this.getMessage("410002"));
        }
    }

    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "入驻企业分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<SettledEnterpriseInfoResult>> page(@RequestBody SettledEnterpriseInfoQueryForm form) {
        SettledEnterpriseInfoQueryParam param = BeanCopyUtils.copyProperties(form, SettledEnterpriseInfoQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return settledEnterpriseInfoService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询入驻企业失败，原因：", e);
            return TerminusResult.fail("410003", this.getMessage("410003"));
        }
    }


    @RequestMapping(value = "/getDetail", method = RequestMethod.POST)
    @ApiOperation(value = "入驻企业详情查询", httpMethod = "POST")
    public TerminusResult<SettledEnterpriseInfoResult> getDetail(@RequestBody SettledEnterpriseInfoGetsForm form) {
        SettledEnterpriseInfoGetsParam param = BeanCopyUtils.copyProperties(form, SettledEnterpriseInfoGetsParam.class);
        try {
            return settledEnterpriseInfoService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询入驻企业详情失败，原因：", e);
            return TerminusResult.fail("410004", this.getMessage("410004"));
        }
    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "修改入驻企业", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody SettledEnterpriseInfoEditForm form) {
        SettledEnterpriseInfoEditParam param = BeanCopyUtils.copyProperties(form, SettledEnterpriseInfoEditParam.class);
        try {
            return settledEnterpriseInfoService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改入驻企业失败，原因：", e);
            return TerminusResult.fail("410006", this.getMessage("410006"));
        }
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "入驻企业删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody SettledEnterpriseInfoDeleteForm form) {
        SettledEnterpriseInfoDeleteParam param = BeanCopyUtils.copyProperties(form, SettledEnterpriseInfoDeleteParam.class);
        try {
            return settledEnterpriseInfoService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("入驻企业删除失败，原因：", e);
            return TerminusResult.fail("410007", this.getMessage("410007"));
        }
    }

    @RequestMapping(value = "/analysisNatureAndIndustry", method = RequestMethod.POST)
    @ApiOperation(value = "签订合同入驻企业行业和性质统计", httpMethod = "POST")
    public TerminusResult<CustomerNatureIndustryResultList> analysisNatureAndIndustry(@RequestBody SettledEnterpriseAnalysisQuery form) {
        SettledEnterpriseAnalysisParam param = BeanCopyUtils.copyProperties(form, SettledEnterpriseAnalysisParam.class);
        try {
            return settledEnterpriseInfoService.analysisSettledEnterpriseWithContract(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("签订合同入驻企业行业和性质统计失败，原因：", e);
            return TerminusResult.fail("410022", this.getMessage("410022"));
        }
    }


    @RequestMapping(value = "/analysisLabel", method = RequestMethod.POST)
    @ApiOperation(value = "签订合同入驻企业标签分类", httpMethod = "POST")
    public TerminusResult<List<SettledEnterpriseLabelNumResult>> analysisSettledEnterpriseLabel(@RequestBody SettledEnterpriseAnalysisQuery form) {
        SettledEnterpriseAnalysisParam param = BeanCopyUtils.copyProperties(form, SettledEnterpriseAnalysisParam.class);
        try {
            return settledEnterpriseInfoService.analysisSettledEnterpriseLabel(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("签订合同入驻企业标签分类统计失败，原因：", e);
            return TerminusResult.fail("410023", this.getMessage("410023"));
        }
    }


}
